home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-12 | 41.1 KB | 1,199 lines |
- ;; Mouse handling for NeXT "Emacs" front end.
- ;; Ripped off of sun-mouse.el
- ;; Copyright (C) 1987 Free Software Foundation, Inc.
-
- ;; This file is NOT part of the standard GNU Emacs distribution.
-
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
-
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
-
- ;;; converted from sun-mouse.el by John G. Myers, Feb 1990.
- ;;; sun-mouse by Jeff Peck, Sun Microsystems, Jan 1987.
- ;;; Original idea by Stan Jefferson
-
- ;;(provide 'eterm-mouse)
-
- ;;;
- ;;; Modelled after the GNUEMACS keymap interface.
- ;;;
- ;;; User Functions:
- ;;; make-mousemap, copy-mousemap,
- ;;; define-mouse, global-set-mouse, local-set-mouse,
- ;;; use-global-mousemap, use-local-mousemap,
- ;;; mouse-lookup, describe-mouse-bindings
- ;;;
- ;;; Options:
- ;;; scrollbar-width
- ;;;
-
- (defvar scrollbar-width 5
- "*The character width of the scrollbar.
- The cursor is deemed to be in the right edge scrollbar if it is this near the
- right edge, and more than two chars past the end of the indicated line.
- Setting to nil limits the scrollbar to the edge or vertical dividing bar.")
-
- ;;;
- ;;; Mousemaps
- ;;;
- (defun make-mousemap ()
- "Returns a new mousemap."
- (cons 'mousemap nil))
-
- (defun copy-mousemap (mousemap)
- "Return a copy of mousemap."
- (copy-alist mousemap))
-
- (defun define-mouse (mousemap mouse-list def)
- "Args MOUSEMAP, MOUSE-LIST, DEF. Define MOUSE-LIST in MOUSEMAP as DEF.
- MOUSE-LIST is a list of atoms specifing a mouse hit according to these rules:
- * One of these atoms specifies the active region of the definition.
- text, scrollbar, modeline, minibuffer
- * One or two or these atoms specify the button or button combination.
- left, middle, right, double
- * Any combination of these atoms specify the active shift keys.
- control, shift, meta
- * With a single unshifted button, you can add
- up
- to indicate an up-click.
- The atom `double' is used with a button designator to denote a double click.
- Two button chords are denoted by listing the two buttons.
- See eterm-mouse-handler for the treatment of the form DEF."
- (mousemap-set (mouse-list-to-mouse-code mouse-list) mousemap def))
-
- (defun global-set-mouse (mouse-list def)
- "Give MOUSE-EVENT-LIST a local definition of DEF.
- See define-mouse for a description of MOUSE-EVENT-LIST and DEF.
- Note that if MOUSE-EVENT-LIST has a local definition in the current buffer,
- that local definition will continue to shadow any global definition."
- (interactive "xMouse event: \nxDefinition: ")
- (define-mouse current-global-mousemap mouse-list def))
-
- (defun local-set-mouse (mouse-list def)
- "Give MOUSE-EVENT-LIST a local definition of DEF.
- See define-mouse for a description of the arguments.
- The definition goes in the current buffer's local mousemap.
- Normally buffers in the same major mode share a local mousemap."
- (interactive "xMouse event: \nxDefinition: ")
- (if (null current-local-mousemap)
- (setq current-local-mousemap (make-mousemap)))
- (define-mouse current-local-mousemap mouse-list def))
-
- (defun use-global-mousemap (mousemap)
- "Selects MOUSEMAP as the global mousemap."
- (setq current-global-mousemap mousemap))
-
- (defun use-local-mousemap (mousemap)
- "Selects MOUSEMAP as the local mousemap.
- nil for MOUSEMAP means no local mousemap."
- (setq current-local-mousemap mousemap))
-
-
- ;;;
- ;;; Interface to the Mouse encoding defined in Emacstool.c
- ;;;
- ;;; Called when mouse-prefix is sent to emacs, additional
- ;;; information is read in as a list (button x y time-delta)
- ;;;
- ;;; First, some generally useful functions:
- ;;;
-
- (defun logtest (x y)
- "True if any bits set in X are also set in Y.
- Just like the Common Lisp function of the same name."
- (not (zerop (logand x y))))
-
-
- ;;;
- ;;; Hit accessors.
- ;;;
-
- (defconst em::ButtonBits 7) ; Lowest 3 bits.
- (defconst em::ShiftmaskBits 56) ; Second lowest 3 bits (56 = 63 - 7).
- (defconst em::DoubleBits 64) ; Bit 7.
- (defconst em::UpBits 128) ; Bit 8.
-
- ;;; All the useful code bits
- (defmacro em::hit-code (hit)
- (` (nth 0 (, hit))))
- ;;; The button, or buttons if a chord.
- (defmacro em::hit-button (hit)
- (` (logand em::ButtonBits (nth 0 (, hit)))))
- ;;; The shift, control, and meta flags.
- (defmacro em::hit-shiftmask (hit)
- (` (logand em::ShiftmaskBits (nth 0 (, hit)))))
- ;;; Set if a double click (but not a chord).
- (defmacro em::hit-double (hit)
- (` (logand em::DoubleBits (nth 0 (, hit)))))
- ;;; Set on button release (as opposed to button press).
- (defmacro em::hit-up (hit)
- (` (logand em::UpBits (nth 0 (, hit)))))
- ;;; Screen x position.
- (defmacro em::hit-x (hit) (list 'nth 1 hit))
- ;;; Screen y position.
- (defmacro em::hit-y (hit) (list 'nth 2 hit))
- ;;; Millisconds since last hit.
- (defmacro em::hit-delta (hit) (list 'nth 3 hit))
-
- (defmacro em::hit-up-p (hit) ; A predicate.
- (` (not (zerop (em::hit-up (, hit))))))
-
- ;;;
- ;;; Loc accessors. for em::window-xy
- ;;;
- (defmacro em::loc-w (loc) (list 'nth 0 loc))
- (defmacro em::loc-x (loc) (list 'nth 1 loc))
- (defmacro em::loc-y (loc) (list 'nth 2 loc))
-
- (defmacro eval-in-buffer (buffer &rest forms)
- "Macro to switches to BUFFER, evaluates FORMS, returns to original buffer."
- ;; When you don't need the complete window context of eval-in-window
- (` (let ((StartBuffer (current-buffer)))
- (unwind-protect
- (progn
- (set-buffer (, buffer))
- (,@ forms))
- (set-buffer StartBuffer)))))
-
- (put 'eval-in-buffer 'lisp-indent-hook 1)
-
- ;;; this is used extensively by sun-fns.el
- ;;;
- (defmacro eval-in-window (window &rest forms)
- "Switch to WINDOW, evaluate FORMS, return to original window."
- (` (let ((OriginallySelectedWindow (selected-window)))
- (unwind-protect
- (progn
- (select-window (, window))
- (,@ forms))
- (select-window OriginallySelectedWindow)))))
- (put 'eval-in-window 'lisp-indent-hook 1)
-
- ;;;
- ;;; handy utility, generalizes window_loop
- ;;;
-
- ;;; It's a macro (and does not evaluate its arguments).
- (defmacro eval-in-windows (form &optional yesmini)
- "Switches to each window and evaluates FORM. Optional argument
- YESMINI says to include the minibuffer as a window.
- This is a macro, and does not evaluate its arguments."
- (` (let ((OriginallySelectedWindow (selected-window)))
- (unwind-protect
- (while (progn
- (, form)
- (not (eq OriginallySelectedWindow
- (select-window
- (next-window nil (, yesmini)))))))
- (select-window OriginallySelectedWindow)))))
- (put 'eval-in-window 'lisp-indent-hook 0)
-
- (defun move-to-loc (x y)
- "Move cursor to window location X, Y.
- Handles wrapped and horizontally scrolled lines correctly."
- (move-to-window-line y)
- ;; window-line-end expects this to return the window column it moved to.
- (let ((cc (current-column))
- (nc (move-to-column
- (if (zerop (window-hscroll))
- (+ (current-column)
- (min (- (window-width) 2) ; To stay on the line.
- x))
- (+ (window-hscroll) -1
- (min (1- (window-width)) ; To stay on the line.
- x))))))
- (- nc cc)))
-
-
- (defun minibuffer-window-p (window)
- "True iff this WINDOW is minibuffer."
- (= (screen-height)
- (nth 3 (window-edges window)) ; The bottom edge.
- ))
-
-
- (defun eterm-mouse-handler (&optional hit)
- "Evaluates the function or list associated with a mouse hit.
- Expecting to read a hit, which is a list: (button x y unused).
- A form bound to button by define-mouse is found by mouse-lookup.
- The variables: *mouse-window*, *mouse-x*, *mouse-y* are bound.
- If the form is a symbol (symbolp), it is funcall'ed with *mouse-window*,
- *mouse-x*, and *mouse-y* as arguments; if the form is a list (listp),
- the form is eval'ed; if the form is neither of these, it is an error.
- Returns nil."
- (interactive)
- (if (null hit) (setq hit (mouse-hit-read)))
- (let ((loc (em::window-xy (em::hit-x hit) (em::hit-y hit))))
- (let ((*mouse-window* (em::loc-w loc))
- (*mouse-x* (em::loc-x loc))
- (*mouse-y* (em::loc-y loc))
- (mouse-code (mouse-event-code hit loc)))
- (let ((form (eval-in-buffer (window-buffer *mouse-window*)
- (mouse-lookup mouse-code))))
- (cond ((null form)
- (if (not (em::hit-up-p hit)) ; undefined up hits are ok.
- (error "Undefined mouse event: %s"
- (prin1-to-string
- (mouse-code-to-mouse-list mouse-code)))))
- ((symbolp form)
- (setq this-command form)
- (funcall form *mouse-window* *mouse-x* *mouse-y*))
- ((listp form)
- (setq this-command (car form))
- (eval form))
- (t
- (error "Mouse action must be symbol or list, but was: %s"
- form))))))
- ;; Don't let 'eterm-mouse-handler get on last-command,
- ;; since this function should be transparent.
- (if (eq this-command 'eterm-mouse-handler)
- (setq this-command last-command))
- ;; (message (prin1-to-string this-command)) ; to see what your buttons did
- nil)
-
- (defun mouse-hit-read ()
- "Read mouse-hit list from keyboard. Like (read 'read-char),
- but that uses minibuffer, and mucks up last-command."
- (let ((char-list nil) (char nil))
- (while (not (equal 13 ; Carriage return.
- (prog1 (setq char (read-char))
- (setq char-list (cons char char-list))))))
- (read (mapconcat 'char-to-string (nreverse char-list) ""))
- ))
-
-
- (defun em::window-xy (x y)
- "Find window containing screen coordinates X and Y.
- Returns list (window x y) where x and y are relative to window."
- (or
- (catch 'found
- (eval-in-windows
- (let ((we (window-edges (selected-window))))
- (let ((le (nth 0 we))
- (te (nth 1 we))
- (re (nth 2 we))
- (be (nth 3 we)))
- (if (= re (screen-width))
- ;; include the continuation column with this window
- (setq re (1+ re)))
- (if (= be (screen-height))
- ;; include partial line at bottom of screen with this window
- ;; id est, if window is not multple of char size.
- (setq be (1+ be)))
-
- (if (and (>= x le) (< x re)
- (>= y te) (< y be))
- (throw 'found
- (list (selected-window) (- x le) (- y te))))))
- t)) ; include minibuffer in eval-in-windows
- ;;If x,y from a real mouse click, we shouldn't get here.
- (list nil x y)
- ))
-
- (defun em::window-region (loc)
- "Parse LOC into a region symbol.
- Returns one of (text scrollbar modeline minibuffer)"
- (let ((w (em::loc-w loc))
- (x (em::loc-x loc))
- (y (em::loc-y loc)))
- (let ((right (1- (window-width w)))
- (bottom (1- (window-height w))))
- (cond ((minibuffer-window-p w) 'minibuffer)
- ((>= y bottom) 'modeline)
- ((>= x right) 'scrollbar)
- ;; far right column (window seperator) is always a scrollbar
- ((and scrollbar-width
- ;; mouse within scrollbar-width of edge.
- (>= x (- right scrollbar-width))
- ;; mouse a few chars past the end of line.
- (>= x (+ 2 (window-line-end w x y))))
- 'scrollbar)
- (t 'text)))))
-
- (defun window-line-end (w x y)
- "Return WINDOW column (ignore X) containing end of line Y"
- (eval-in-window w (save-excursion (move-to-loc (screen-width) y))))
-
- ;;;
- ;;; The encoding of mouse events into a mousemap.
- ;;; These values must agree with coding in emacstool:
- ;;;
- (defconst em::keyword-alist
- '((left . 1) (middle . 2) (right . 4)
- (shift . 8) (control . 16) (meta . 32) (double . 64) (up . 128)
- (text . 256) (scrollbar . 512) (modeline . 1024) (minibuffer . 2048)
- ))
-
- (defun mouse-event-code (hit loc)
- "Maps MOUSE-HIT and LOC into a mouse-code."
- ;;;Region is a code for one of text, modeline, scrollbar, or minibuffer.
- (logior (em::hit-code hit)
- (mouse-region-to-code (em::window-region loc))))
-
- (defun mouse-region-to-code (region)
- "Returns partial mouse-code for specified REGION."
- (cdr (assq region em::keyword-alist)))
-
- (defun mouse-list-to-mouse-code (mouse-list)
- "Map a MOUSE-LIST to a mouse-code."
- (apply 'logior
- (mapcar (function (lambda (x)
- (cdr (assq x em::keyword-alist))))
- mouse-list)))
-
- (defun mouse-code-to-mouse-list (mouse-code)
- "Map a MOUSE-CODE to a mouse-list."
- (apply 'nconc (mapcar
- (function (lambda (x)
- (if (logtest mouse-code (cdr x))
- (list (car x)))))
- em::keyword-alist)))
-
- (defun mousemap-set (code mousemap value)
- (let* ((alist (cdr mousemap))
- (assq-result (assq code alist)))
- (if assq-result
- (setcdr assq-result value)
- (setcdr mousemap (cons (cons code value) alist)))))
-
- (defun mousemap-get (code mousemap)
- (cdr (assq code (cdr mousemap))))
-
- (defun mouse-lookup (mouse-code)
- "Look up MOUSE-EVENT and return the definition. nil means undefined."
- (or (mousemap-get mouse-code current-local-mousemap)
- (mousemap-get mouse-code current-global-mousemap)))
-
- ;;;
- ;;; I (jpeck) don't understand the utility of the next four functions
- ;;; ask Steven Greenbaum <froud@kestrel>
- ;;;
- (defun mouse-mask-lookup (mask list)
- "Args MASK (a bit mask) and LIST (a list of (code . form) pairs).
- Returns a list of elements of LIST whose code or'ed with MASK is non-zero."
- (let ((result nil))
- (while list
- (if (logtest mask (car (car list)))
- (setq result (cons (car list) result)))
- (setq list (cdr list)))
- result))
-
- (defun mouse-union (l l-unique)
- "Return the union of list of mouse (code . form) pairs L and L-UNIQUE,
- where L-UNIQUE is considered to be union'ized already."
- (let ((result l-unique))
- (while l
- (let ((code-form-pair (car l)))
- (if (not (assq (car code-form-pair) result))
- (setq result (cons code-form-pair result))))
- (setq l (cdr l)))
- result))
-
- (defun mouse-union-first-prefered (l1 l2)
- "Return the union of lists of mouse (code . form) pairs L1 and L2,
- based on the code's, with preference going to elements in L1."
- (mouse-union l2 (mouse-union l1 nil)))
-
- (defun mouse-code-function-pairs-of-region (region)
- "Return a list of (code . function) pairs, where each code is
- currently set in the REGION."
- (let ((mask (mouse-region-to-code region)))
- (mouse-union-first-prefered
- (mouse-mask-lookup mask (cdr current-local-mousemap))
- (mouse-mask-lookup mask (cdr current-global-mousemap))
- )))
-
- ;;;
- ;;; Functions for DESCRIBE-MOUSE-BINDINGS
- ;;; And other mouse documentation functions
- ;;; Still need a good procedure to print out a help sheet in readable format.
- ;;;
-
- (defun one-line-doc-string (function)
- "Returns first line of documentation string for FUNCTION.
- If there is no documentation string, then the string
- \"No documentation\" is returned."
- (while (consp function) (setq function (car function)))
- (let ((doc (documentation function)))
- (if (null doc)
- "No documentation."
- (string-match "^.*$" doc)
- (substring doc 0 (match-end 0)))))
-
- (defun print-mouse-format (binding)
- (princ (car binding))
- (princ ": ")
- (mapcar (function
- (lambda (mouse-list)
- (princ mouse-list)
- (princ " ")))
- (cdr binding))
- (terpri)
- (princ " ")
- (princ (one-line-doc-string (car binding)))
- (terpri)
- )
-
- (defun print-mouse-bindings (region)
- "Prints mouse-event bindings for REGION."
- (mapcar 'print-mouse-format (em::event-bindings region)))
-
- (defun em::event-bindings (region)
- "Returns an alist of (function . (mouse-list1 ... mouse-listN)) for REGION,
- where each mouse-list is bound to the function in REGION."
- (let ((mouse-bindings (mouse-code-function-pairs-of-region region))
- (result nil))
- (while mouse-bindings
- (let* ((code-function-pair (car mouse-bindings))
- (current-entry (assoc (cdr code-function-pair) result)))
- (if current-entry
- (setcdr current-entry
- (cons (mouse-code-to-mouse-list (car code-function-pair))
- (cdr current-entry)))
- (setq result (cons (cons (cdr code-function-pair)
- (list (mouse-code-to-mouse-list
- (car code-function-pair))))
- result))))
- (setq mouse-bindings (cdr mouse-bindings))
- )
- result))
-
- (defun describe-mouse-bindings ()
- "Lists all current mouse-event bindings."
- (interactive)
- (with-output-to-temp-buffer "*Help*"
- (princ "Text Region") (terpri)
- (princ "---- ------") (terpri)
- (print-mouse-bindings 'text) (terpri)
- (princ "Modeline Region") (terpri)
- (princ "-------- ------") (terpri)
- (print-mouse-bindings 'modeline) (terpri)
- (princ "Scrollbar Region") (terpri)
- (princ "--------- ------") (terpri)
- (print-mouse-bindings 'scrollbar)))
-
- (defun describe-mouse-briefly (mouse-list)
- "Print a short description of the function bound to MOUSE-LIST."
- (interactive "xDescibe mouse list briefly: ")
- (let ((function (mouse-lookup (mouse-list-to-mouse-code mouse-list))))
- (if function
- (message "%s runs the command %s" mouse-list function)
- (message "%s is undefined" mouse-list))))
-
-
- ;;;
- ;;; initialize mouse maps
- ;;;
-
- (make-variable-buffer-local 'current-local-mousemap)
- (setq-default current-local-mousemap nil)
- (defvar current-global-mousemap (make-mousemap))
- ;; Low-level subroutines for NeXT "Emacs" front end
- ;; Copyright (C) 1990 Free Software Foundation, Inc.
-
- ;; This file is NOT part of the standard GNU Emacs distribution.
-
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
-
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
-
- ;;; Apr 4 '90 jgm Ripped off of sun-fns.el
-
- ;;(provide 'eterm-low)
-
- (defun eterm-send-terminal-string-function (string function)
- "Send a \\C-q quoted string to the terminal, then send function"
- (send-string-to-terminal (concat "\C-q" string "\377" function)))
-
- (defun eterm-change-title (title)
- "Change the wm title for the gnumacs window."
- (interactive "sTitle: ")
- (eterm-send-terminal-string-function title "t"))
-
- ;(defun global-set-menu (item command)
- ; "Add a command to the wm menus."
- ; (interactive "sMenu item: \nCCommand: ")
- ; (eterm-send-terminal-string-function
- ; (concat item ":\C-[x" (prin1-to-string command) "\n") "m"))
- ;
- ;(defun global-unset-menu (item)
- ; "Remove a menu item from the wm menus."
- ; (interactive "sMenu item: ")
- ; (eterm-send-terminal-string-function item "m"))
- ;
- ;(defun add-menu-item (item binding &optional page)
- ; "Add a menu item to the menus. (obsolete)"
- ; (interactive "sItem: \nsBinding: \nsPage: ")
- ; (eterm-send-terminal-string-function
- ; (concat page (and page ", ")
- ; item (and binding (not (string= binding "")) ":") binding)
- ; "m"))
- ;
- ;(defun remove-menu-item (item &optional page)
- ; "Remove ITEM from the wm menus. (obsolete)"
- ; (interactive "sItem: \nsPage:")
- ; (add-menu-item item "" page))
-
- ; something to hide without using the mouse
- ;(defun eterm-hide-emacs ()
- ; "Ask the termulator to hide this window."
- ; (interactive)
- ; (send-string-to-terminal "\C-z"))
-
- ; cut buffer stuff
-
- (defun eterm-send-region-to-cut-buffer ()
- " Copy the region between point and mark to the NeXT cut buffer.
- This will not happen if the region contains a \\377."
- (interactive "")
- (save-excursion
- ;; We get our own values for the region, so we can trap the error
- ;; if there is none.
- (condition-case err
- (let ((start (region-beginning))
- (end (region-end)))
- (goto-char start)
- (if (search-forward "\377" end t)
- (progn
- (eterm-send-terminal-string-function "" "c")
- (message "Bogus character in region."))
- (eterm-send-terminal-string-function
- (buffer-substring start end) "c")))
- ;;
- ;; The region is empty, send a nil region out and continue.
- (error (eterm-send-terminal-string-function "" "c")))))
-
- (defun eterm-send-region-to-cut-buffer-and-wipe ()
- " As send-region-to-cut-buffer but also kill the text."
- (interactive "")
- (barf-if-buffer-read-only)
- (eterm-send-region-to-cut-buffer)
- (call-interactively 'kill-region))
-
- ;
- ; Event server stuff
- ;
-
- (defvar eserver nil
- "The event server process.")
-
- (defun start-event-server ()
- (interactive)
- (eterm-change-title (concat "Emacs version " emacs-version))
- (let ((host (or (getenv "EVENT_HOST")
- (error "Can't find host for event server")))
- (port (or (getenv "EVENT_PORT")
- (error "Can't find port for event server"))))
- (setq eserver
- (open-network-stream " event-server" nil host
- (string-to-int port))))
- (set-process-filter eserver 'event-filter)
- (set-process-sentinel eserver 'event-sentinel)
- (global-set-key "\C-x\C-@" 'eterm-mouse-handler))
-
- (defun event-sentinel (process change)
- (message (concat "The event handler has " change)))
-
- (defvar event-partial-output ""
- "Incomplete, unprocessed output from the event server")
-
- ;;; Modified by J. Gregory 17-Oct-91. Save match-end before match
- ;;; data gets crunched.
- (defun event-filter (process string)
- ;; Add the incoming string to what we have:
- (let ((events (concat event-partial-output string)))
- ;; Each event is terminated with a newline.
- ;; Process events until we run out of newlines.
- (while (string-match "\n" events) ;sets match-data
- (let ((next (match-end 0)))
- (eval (car (read-from-string events)))
- (setq events (substring events next))))
- ;; Set global to be what we have not yet processed
- (setq event-partial-output events)))
-
- ; Handlers for the events that get sent to us.
- ;
- (defun event-copy ()
- (eterm-send-region-to-cut-buffer))
-
- (defun event-cut ()
- (eterm-send-region-to-cut-buffer-and-wipe))
-
- (defun event-paste (str)
- (barf-if-buffer-read-only)
- (push-mark (point))
- (insert str))
-
- (defun event-quit ()
- (save-buffers-kill-emacs)
- (setq last-command 'save-buffers-kill-emacs))
-
- ;(defun event-resize (newx newy)
- ; (if (or (not (= (screen-width) newx))
- ; (not (= (screen-height) newy)))
- ; (progn
- ; (set-screen-width newx)
- ; (set-screen-height newy))
- ; (redraw-display)))
-
-
- ;; Subroutines of Mouse handling for NeXT "Emacs" front end
- ;; Ripped off of the Sun windows support code
- ;; Copyright (C) 1987 Free Software Foundation, Inc.
-
- ;; This file is NOT part of the standard GNU Emacs distribution.
-
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
-
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
-
- ;;; Apr 4 '90 jgm Ripped off of sun-fns.el
- ;;(provide 'eterm-fns)
- ;;(require 'eterm-mouse)
- ;;;
- ;;; Functions for manipulating via the mouse and mouse-map definitions
- ;;; for accessing them. Also definitons of mouse menus.
- ;;; This file you should freely modify to reflect you personal tastes.
- ;;;
- ;;; First half of file defines functions to implement mouse commands,
- ;;; Don't delete any of those, just add what ever else you need.
- ;;; Second half of file defines mouse bindings, do whatever you want there.
-
- ;;;
- ;;; Mouse Functions.
- ;;;
- ;;; These functions follow the eterm-mouse-handler convention of being called
- ;;; with three arguements: (window x-pos y-pos)
- ;;; This makes it easy for a mouse executed command to know where the mouse is.
- ;;; Use the macro "eval-in-window" to execute a function
- ;;; in a temporarily selected window.
- ;;;
- ;;; If you have a function that must be called with other arguments
- ;;; bind the mouse button to an s-exp that contains the necessary parameters.
- ;;; See "minibuffer" bindings for examples.
- ;;;
- (defconst cursor-pause-milliseconds 300
- "*Number of milliseconds to display alternate cursor (usually the mark)")
-
- (defun indicate-region (&optional pause)
- "Bounce cursor to mark for cursor-pause-milliseconds and back again"
- (or pause (setq pause cursor-pause-milliseconds))
- (let ((times 0))
- (exchange-point-and-mark)
- (if (fboundp 'sit-for-millisecs)
- (sit-for-millisecs pause)
- (sit-for 1))
- (exchange-point-and-mark)))
-
- ; (while (< times 20)
- ; (sit-for 0)
- ; (setq times (1+ times))))
-
-
- ;;;
- ;;; Text buffer operations
- ;;;
- (defun mouse-move-point (window x y)
- "Move point to mouse cursor."
- (select-window window)
- (move-to-loc x y)
- (if (memq last-command ; support the mouse-copy/delete/yank
- '(mouse-copy mouse-delete mouse-yank-move))
- (setq this-command 'mouse-yank-move))
- )
-
- (defun mouse-set-mark (window x y)
- "Set mark at mouse cursor."
- (eval-in-window window ;; use this to get the unwind protect
- (let ((point (point)))
- (move-to-loc x y)
- (set-mark (point))
- (goto-char point)
- (indicate-region)))
- )
-
- (defun mouse-set-mark-and-select (window x y)
- "Set mark at mouse cursor, and select that window."
- (select-window window)
- (mouse-set-mark window x y)
- )
-
- ;;;
- ;;; Simple mouse dragging stuff: marking with button up
- ;;;
-
- (defvar *mouse-drag-window* nil)
- (defvar *mouse-drag-x* -1)
- (defvar *mouse-drag-y* -1)
-
- (defun mouse-drag-move-point (window x y)
- "Move point to mouse cursor, and allow dragging."
- (mouse-move-point window x y)
- (setq *mouse-drag-window* window
- *mouse-drag-x* x
- *mouse-drag-y* y))
-
- (defun mouse-drag-set-mark (window x y)
- "The up click handler that goes with mouse-drag-move-point.
- If mouse is in same WINDOW but at different X or Y than when
- mouse-drag-move-point was last executed, set the mark at mouse."
- (if (and (eq *mouse-drag-window* window)
- (not (and (equal *mouse-drag-x* x)
- (equal *mouse-drag-y* y))))
- (mouse-set-mark-and-select window x y)
- (setq this-command last-command)) ; this was just an upclick no-op.
- )
-
- (defun mouse-select-or-drag-move-point (window x y)
- "Select window if not selected, otherwise do mouse-drag-move-point."
- (if (eq (selected-window) window)
- (mouse-drag-move-point window x y)
- (mouse-select-window window x y)))
-
- ;;;
- ;;; esoteria:
- ;;;
- (defun mouse-exch-pt-and-mark (window x y)
- "Exchange point and mark."
- (select-window window)
- (exchange-point-and-mark)
- )
-
- (defun mouse-call-kbd-macro (window x y)
- "Invokes last keyboard macro at mouse cursor."
- (mouse-move-point window x y)
- (call-last-kbd-macro)
- )
-
- (defun mouse-mark-thing (window x y)
- "Set point and mark to text object using syntax table.
- The resulting region is put in the NeXT pasteboard.
- Left or right Paren syntax marks an s-expression.
- Clicking at the end of a line marks the line including a trailing newline.
- If it doesn't recognize one of these it marks the character at point."
- (mouse-move-point window x y)
- (if (eobp) (open-line 1))
- (let* ((char (char-after (point)))
- (syntax (char-syntax char)))
- (cond
- ((eq syntax ?w) ; word.
- (forward-word 1)
- (set-mark (point))
- (forward-word -1))
- ;; try to include a single following whitespace (is this a good idea?)
- ;; No, not a good idea since inconsistent.
- ;;(if (eq (char-syntax (char-after (mark))) ?\ )
- ;; (set-mark (1+ (mark))))
- ((eq syntax ?\( ) ; open paren.
- (mark-sexp 1))
- ((eq syntax ?\) ) ; close paren.
- (forward-char 1)
- (mark-sexp -1)
- (exchange-point-and-mark))
- ((eolp) ; mark line if at end.
- (set-mark (1+ (point)))
- (beginning-of-line 1))
- (t ; mark character
- (set-mark (1+ (point)))))
- (indicate-region)) ; display region boundary.
- )
-
- (defun mouse-kill-thing (window x y)
- "Kill thing at mouse, and put point there."
- (mouse-mark-thing window x y)
- (eterm-send-region-to-cut-buffer-and-wipe (region-beginning) (region-end))
- )
-
- (defun mouse-kill-thing-there (window x y)
- "Kill thing at mouse, leave point where it was.
- See mouse-mark-thing for a description of the objects recognized."
- (eval-in-window window
- (save-excursion
- (mouse-mark-thing window x y)
- (eterm-send-region-to-cut-buffer-and-wipe (region-beginning) (region-end))))
- )
-
- (defun mouse-save-thing (window x y &optional quiet)
- "Put thing at mouse in kill ring.
- See mouse-mark-thing for a description of the objects recognized."
- (mouse-mark-thing window x y)
- (eterm-send-region-to-cut-buffer (region-beginning) (region-end))
- (if (not quiet) (message "Thing saved"))
- )
-
- (defun mouse-save-thing-there (window x y &optional quiet)
- "Put thing at mouse in kill ring, leave point as is.
- See mouse-mark-thing for a description of the objects recognized."
- (eval-in-window window
- (save-excursion
- (mouse-save-thing window x y quiet))))
-
- ;;;
- ;;; Mouse yanking...
- ;;;
- (defun mouse-copy-thing (window x y)
- "Put thing at mouse in kill ring, yank to point.
- See mouse-mark-thing for a description of the objects recognized."
- (setq last-command 'not-kill) ;Avoids appending to previous kills.
- (mouse-save-thing-there window x y t)
- (yank)
- (setq this-command 'yank))
-
- (defun mouse-move-thing (window x y)
- "Kill thing at mouse, yank it to point.
- See mouse-mark-thing for a description of the objects recognized."
- (setq last-command 'not-kill) ;Avoids appending to previous kills.
- (mouse-kill-thing-there window x y)
- (yank)
- (setq this-command 'yank))
-
- (defun mouse-yank-at-point (&optional window x y)
- "Yank from kill-ring at point; then cycle thru kill ring."
- (if (eq last-command 'yank)
- (let ((before (< (point) (mark))))
- (delete-region (point) (mark))
- (rotate-yank-pointer 1)
- (insert (car kill-ring-yank-pointer))
- (if before (exchange-point-and-mark)))
- (yank))
- (setq this-command 'yank))
-
- (defun mouse-yank-at-mouse (window x y)
- "Yank from kill-ring at mouse; then cycle thru kill ring."
- (mouse-move-point window x y)
- (mouse-yank-at-point window x y))
-
- (defun mouse-save/delete/yank (&optional window x y)
- "Context sensitive save/delete/yank.
- Consecutive clicks perform as follows:
- * first click saves region to kill ring,
- * second click kills region,
- * third click yanks from kill ring,
- * subsequent clicks cycle thru kill ring.
- If mouse-move-point is performed after the first or second click,
- the next click will do a yank, etc. Except for a possible mouse-move-point,
- this command is insensitive to mouse location."
- (cond
- ((memq last-command '(mouse-delete yank mouse-yank-move)) ; third+ click
- (mouse-yank-at-point))
- ((eq last-command 'mouse-copy) ; second click
- (kill-region (region-beginning) (region-end))
- (setq this-command 'mouse-delete))
- (t ; first click
- (copy-region-as-kill (region-beginning) (region-end))
- (message "Region saved")
- (setq this-command 'mouse-copy))
- ))
-
-
- (defun mouse-split-horizontally (window x y)
- "Splits the window horizontally at mouse cursor."
- (eval-in-window window (split-window-horizontally (1+ x))))
-
- (defun mouse-split-vertically (window x y)
- "Split the window vertically at the mouse cursor."
- (eval-in-window window (split-window-vertically (1+ y))))
-
- (defun mouse-select-window (window x y)
- "Selects the window, restoring point."
- (select-window window))
-
- (defun mouse-delete-other-windows (window x y)
- "Deletes all windows except the one mouse is in."
- (delete-other-windows window))
-
- (defun mouse-delete-window (window x y)
- "Deletes the window mouse is in."
- (delete-window window))
-
- (defun mouse-undo (window x y)
- "Invokes undo in the window mouse is in."
- (eval-in-window window (undo)))
-
- ;;;
- ;;; Scroll operations
- ;;;
-
- ;;; The move-to-window-line is used below because otherwise
- ;;; scrolling a non-selected process window with the mouse, after
- ;;; the process has written text past the bottom of the window,
- ;;; gives an "End of buffer" error, and then scrolls. The
- ;;; move-to-window-line seems to force recomputing where things are.
- (defun mouse-scroll-up (window x y)
- "Scrolls the window upward."
- (eval-in-window window (move-to-window-line 1) (scroll-up nil)))
-
- (defun mouse-scroll-down (window x y)
- "Scrolls the window downward."
- (eval-in-window window (scroll-down nil)))
-
- (defun mouse-scroll-proportional (window x y)
- "Scrolls the window proportionally corresponding to window
- relative X divided by window width."
- (eval-in-window window
- (if (>= x (1- (window-width)))
- ;; When x is maximun (equal to or 1 less than window width),
- ;; goto end of buffer. We check for this special case
- ;; becuase the calculated goto-char often goes short of the
- ;; end due to roundoff error, and we often really want to go
- ;; to the end.
- (goto-char (point-max))
- (progn
- (goto-char (+ (point-min) ; For narrowed regions.
- (* x (/ (- (point-max) (point-min))
- (1- (window-width))))))
- (beginning-of-line))
- )
- (what-cursor-position) ; Report position.
- ))
-
- (defun mouse-line-to-top (window x y)
- "Scrolls the line at the mouse cursor up to the top."
- (eval-in-window window (scroll-up y)))
-
- (defun mouse-top-to-line (window x y)
- "Scrolls the top line down to the mouse cursor."
- (eval-in-window window (scroll-down y)))
-
- (defun mouse-line-to-bottom (window x y)
- "Scrolls the line at the mouse cursor to the bottom."
- (eval-in-window window (scroll-up (+ y (- 2 (window-height))))))
-
- (defun mouse-bottom-to-line (window x y)
- "Scrolls the bottom line up to the mouse cursor."
- (eval-in-window window (scroll-down (+ y (- 2 (window-height))))))
-
- (defun mouse-line-to-middle (window x y)
- "Scrolls the line at the mouse cursor to the middle."
- (eval-in-window window (scroll-up (- y -1 (/ (window-height) 2)))))
-
- (defun mouse-middle-to-line (window x y)
- "Scrolls the line at the middle to the mouse cursor."
- (eval-in-window window (scroll-up (- (/ (window-height) 2) y 1))))
-
-
-
- ;;;
- ;;; minibuffer
- ;;;
- (defun mini-move-point (window x y)
- ;; -6 is good for most common cases
- (mouse-move-point window (- x 6) 0))
-
- (defun mini-set-mark-and-select (window x y)
- ;; -6 is good for most common cases
- (mouse-set-mark-and-select window (- x 6) 0))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Buffer-mode Mouse commands
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun Buffer-at-mouse (w x y)
- "Calls Buffer-menu-buffer from mouse click."
- (save-window-excursion
- (mouse-move-point w x y)
- (beginning-of-line)
- (Buffer-menu-buffer t)))
-
- (defun mouse-buffer-bury (w x y)
- "Bury the indicated buffer."
- (bury-buffer (Buffer-at-mouse w x y))
- )
-
- (defun mouse-buffer-select (w x y)
- "Put the indicated buffer in selected window."
- (switch-to-buffer (Buffer-at-mouse w x y))
- (list-buffers)
- )
-
- (defun mouse-buffer-delete (w x y)
- "mark indicated buffer for delete"
- (save-window-excursion
- (mouse-move-point w x y)
- (Buffer-menu-delete)
- ))
-
- (defun mouse-buffer-execute (w x y)
- "execute buffer-menu selections"
- (save-window-excursion
- (mouse-move-point w x y)
- (Buffer-menu-execute)
- ))
-
- (defun enable-mouse-in-buffer-list ()
- "Call this to enable mouse selections in *Buffer List*
- LEFT puts the indicated buffer in the selected window.
- SHIFT-LEFT buries the indicated buffer.
- RIGHT marks the indicated buffer for deletion.
- SHIFT-RIGHT deletes the marked buffers.
- To unmark a buffer marked for deletion, select it with LEFT."
- (save-window-excursion
- (list-buffers) ; Initialize *Buffer List*
- (set-buffer "*Buffer List*")
- (local-set-mouse '(text shift left) 'mouse-buffer-bury)
- (local-set-mouse '(text left) 'mouse-buffer-select)
- (local-set-mouse '(text right) 'mouse-buffer-delete)
- (local-set-mouse '(text shift right) 'mouse-buffer-execute)
- )
- )
-
-
- ;;;*******************************************************************
- ;;;
- ;;; Global Mouse Bindings.
- ;;;
- ;;; There is some sense to this mouse binding madness:
- ;;; LEFT and RIGHT scrolls are inverses.
- ;;; SHIFT makes an opposite meaning in the scroll bar.
- ;;; META makes the scrollbar functions work in the text region.
- ;;; RIGHT operates the mark
- ;;; LEFT operates at point
-
- ;;; META commands are generally non-destructive,
- ;;; SHIFT is a little more dangerous.
- ;;; CONTROL is for the really complicated ones.
-
- ;;; CONTROL-META-SHIFT-RIGHT gives help on that region.
- ;;; (or so it would if I had time to implement it --jgm)
-
- ;;;
- ;;; Text Region mousemap
- ;;;
- ;; The basics: Point, Mark, Menu, Sun-Select:
- (global-set-mouse '(text left) 'mouse-drag-move-point)
- (global-set-mouse '(text up left) 'mouse-drag-set-mark)
- (global-set-mouse '(text shift left) 'mouse-exch-pt-and-mark)
-
- (global-set-mouse '(text right) 'mouse-set-mark-and-select)
-
- ;; The Slymoblics multi-command for Save, Kill, Copy, Move:
- (global-set-mouse '(text shift right) 'mouse-save/delete/yank)
-
- ;; Save, Kill, Copy, Move Things:
- ;; control-left composes with control middle/right to produce copy/move
- (global-set-mouse '(text control right ) 'mouse-save-thing-there)
- ;(global-set-mouse '(text control right ) 'mouse-kill-thing-there)
- (global-set-mouse '(text control left) 'mouse-yank-at-point)
-
- ;(global-set-mouse '(text control middle left) 'mouse-copy-thing)
- ;(global-set-mouse '(text control right left) 'mouse-move-thing)
- ;(global-set-mouse '(text control right middle) 'mouse-mark-thing)
-
- ;; The Universal mouse help command (press all buttons):
- ;(global-set-mouse '(text shift control meta right) 'mouse-help-region)
-
- ;;; Meta in Text Region is like meta version in scrollbar:
- (global-set-mouse '(text meta left) 'mouse-line-to-top)
- (global-set-mouse '(text meta shift left) 'mouse-line-to-bottom)
- ;(global-set-mouse '(text meta middle) 'mouse-line-to-middle)
- ;(global-set-mouse '(text meta shift middle) 'mouse-middle-to-line)
- ;(global-set-mouse '(text meta control middle) 'mouse-split-vertically)
- (global-set-mouse '(text meta right) 'mouse-top-to-line)
- (global-set-mouse '(text meta shift right) 'mouse-bottom-to-line)
-
- ;; Miscellaneous:
- (global-set-mouse '(text meta control left) 'mouse-call-kbd-macro)
- (global-set-mouse '(text meta control right) 'mouse-undo)
-
- ;;;
- ;;; Scrollbar mousemap.
- ;;; Are available in the Scrollbar Region, or with Meta Text (or Meta Scrollbar)
- ;;;
- (global-set-mouse '(scrollbar left) 'mouse-line-to-top)
- (global-set-mouse '(scrollbar shift left) 'mouse-line-to-bottom)
-
- ;(global-set-mouse '(scrollbar middle) 'mouse-line-to-middle)
- ;(global-set-mouse '(scrollbar shift middle) 'mouse-middle-to-line)
- ;(global-set-mouse '(scrollbar control middle) 'mouse-split-vertically)
-
- (global-set-mouse '(scrollbar right) 'mouse-top-to-line)
- (global-set-mouse '(scrollbar shift right) 'mouse-bottom-to-line)
-
- (global-set-mouse '(scrollbar meta left) 'mouse-line-to-top)
- (global-set-mouse '(scrollbar meta shift left) 'mouse-line-to-bottom)
- ;(global-set-mouse '(scrollbar meta middle) 'mouse-line-to-middle)
- ;(global-set-mouse '(scrollbar meta shift middle) 'mouse-middle-to-line)
- ;(global-set-mouse '(scrollbar meta control middle) 'mouse-split-vertically)
- (global-set-mouse '(scrollbar meta right) 'mouse-top-to-line)
- (global-set-mouse '(scrollbar meta shift right) 'mouse-bottom-to-line)
-
- ;; And the help menu:
- ;(global-set-mouse '(scrollbar shift control meta right) 'mouse-help-region)
-
- ;;;
- ;;; Modeline mousemap.
- ;;;
- ;;; Note: meta of any single button selects window.
-
- (global-set-mouse '(modeline left) 'mouse-scroll-up)
- (global-set-mouse '(modeline meta left) 'mouse-select-window)
-
- ;(global-set-mouse '(modeline middle) 'mouse-scroll-proportional)
- ;(global-set-mouse '(modeline meta middle) 'mouse-select-window)
- ;(global-set-mouse '(modeline control middle) 'mouse-split-horizontally)
-
- (global-set-mouse '(modeline right) 'mouse-scroll-down)
- (global-set-mouse '(modeline meta right) 'mouse-select-window)
-
- ;;; control-left selects this window, control-right deletes it.
- (global-set-mouse '(modeline control left) 'mouse-delete-other-windows)
- (global-set-mouse '(modeline control right) 'mouse-delete-window)
-
- ;; in case of confusion, just select it:
- (global-set-mouse '(modeline control left right)'mouse-select-window)
-
- ;; even without confusion (and without the keyboard) select it:
- (global-set-mouse '(modeline left right) 'mouse-select-window)
-
- ;; And the help menu:
- ;(global-set-mouse '(modeline shift control meta right) 'mouse-help-region)
-
- ;;;
- ;;; Minibuffer Mousemap
- ;;; Demonstrating some variety:
- ;;;
- (global-set-mouse '(minibuffer left) 'mini-move-point)
- (global-set-mouse '(minibuffer right) 'mini-set-mark-and-select)
-
- (global-set-mouse '(minibuffer shift left) '(previous-complex-command 1))
- (global-set-mouse '(minibuffer control left) '(next-complex-command 1))
-
- (global-set-mouse '(minibuffer shift right) '(next-complex-command 1))
- (global-set-mouse '(minibuffer control right) '(previous-complex-command 1))
-
- ;(global-set-mouse '(minibuffer shift control meta right) 'mouse-help-region)
-